home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gnugo1_1.lha / gnugo / findpatn.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  4KB  |  191 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37.  
  38. #define EMPTY 0
  39.  
  40. extern unsigned char p[19][19];
  41. extern int mymove, umove;
  42. extern int opn[9];
  43.  
  44. findpatn(i, j, val)
  45. /* find pattern to match for next move */
  46. int *i, *j, *val;
  47. {
  48.  int m, n;
  49.  int ti, tj, tval;
  50.  static int cnd, mtype;  /* game tree node number, move type */
  51. /* mtype = 0, basic; 1, inverted; 2, reflected; 3, inverted & reflected */
  52.  
  53. /* open game then occupy corners */
  54.  if (opn[4])   /* continue last move */
  55.    {
  56.     opn[4] = 0;  /* clear flag */
  57.     if (opening(i, j, &cnd, mtype)) opn[4] = 1; /* more move then reset flag */
  58.     if (p[*i][*j] == EMPTY)  /* valid move */
  59.       {
  60.        *val = 80;
  61.        return 1;
  62.      }
  63.     else
  64.       opn[4] = 0;
  65.   }
  66.  
  67.  if (opn[0])   /* Northwest corner */
  68.    {
  69.     opn[0] = 0;  /* clear flag */
  70.     if (openregion(0, 0, 5, 5))
  71.       {
  72.        cnd = 0;
  73.        mtype = 0;
  74.        opening(i, j, &cnd, mtype);  /* get new node for next move */
  75.        if (opening(i, j, &cnd, mtype)) opn[4] = 1;
  76.        *val = 80;
  77.        return 1;
  78.      }
  79.  }
  80.  
  81.  if (opn[1])   /* Southwest corner */
  82.    {
  83.     opn[1] = 0;
  84.     if (openregion(13, 0, 18, 5))
  85.       {
  86.        cnd = 0;
  87.        mtype = 1;
  88.        opening(i, j, &cnd, mtype);  /* get new node for next move */
  89.        if (opening(i, j, &cnd, mtype)) opn[4] = 1;
  90.        *val = 80;
  91.        return 1;
  92.      }
  93.   }
  94.  
  95.  if (opn[2])   /* Northeast corner */
  96.    {
  97.     opn[2] = 0;
  98.     if (openregion(0, 13, 5, 18))
  99.       {
  100.        cnd = 0;
  101.        mtype = 2;
  102.        opening(i, j, &cnd, mtype);  /* get new node for next move */
  103.        if (opening(i, j, &cnd, mtype)) opn[4] = 1;
  104.        *val = 80;
  105.        return 1;
  106.      }
  107.   }
  108.  
  109.  if (opn[3])   /* Northeast corner */
  110.    {
  111.     opn[3] = 0;
  112.     if (openregion(13, 13, 18, 18))
  113.       {
  114.        cnd = 0;
  115.        mtype = 3;
  116.        opening(i, j, &cnd, mtype);  /* get new node for next move */
  117.        if (opening(i, j, &cnd, mtype)) opn[4] = 1;
  118.        *val = 80;
  119.        return 1;
  120.      }
  121.   }
  122.  
  123. /* occupy edges */
  124.  if (opn[5])   /* North edge */
  125.    {
  126.     opn[5] = 0;
  127.     if (openregion(0, 6, 4, 11))
  128.       {
  129.        *i = 3;
  130.        *j = 9;
  131.        *val = 80;
  132.        return 1;
  133.      }
  134.   }
  135.  
  136.  if (opn[6])   /* South edge */
  137.    {
  138.     opn[6] = 0;
  139.     if (openregion(18, 6, 14, 11))
  140.       {
  141.        *i = 15;
  142.        *j = 9;
  143.        *val = 80;
  144.        return 1;
  145.      }
  146.   }
  147.  
  148.  if (opn[7])   /* West edge */
  149.    {
  150.     opn[7] = 0;
  151.     if (openregion(6, 0, 11, 4))
  152.       {
  153.        *i = 9;
  154.        *j = 3;
  155.        *val = 80;
  156.        return 1;
  157.      }
  158.   }
  159.  
  160.  if (opn[8])   /* East edge */
  161.    {
  162.     opn[8] = 0;
  163.     if (openregion(6, 18, 11, 14))
  164.       {
  165.        *i = 9;
  166.        *j = 15;
  167.        *val = 80;
  168.        return 1;
  169.      }
  170.   }
  171.  
  172.  *i = -1;
  173.  *j = -1;
  174.  *val = -1;
  175.  
  176. /* find local pattern */
  177.  for (m = 0; m < 19; m++)
  178.    for (n = 0; n < 19; n++)
  179.      if ((p[m][n] == mymove) &&
  180.          (matchpat(m, n, &ti, &tj, &tval) && (tval > *val)))
  181.        {
  182.         *val = tval;
  183.         *i = ti;
  184.         *j = tj;
  185.       }
  186.  if (*val > 0)  /* pattern found */
  187.     return 1;
  188.  else  /* no match found */
  189.     return 0;
  190. }  /* end findpatn */
  191.